package org.lanqiao.music.common.utils;

import lombok.Data;

/*
   controller 中通用的返回类
 */
@Data
public class Result<T> {
    //返回的状态吗
    private Integer code ;
    //返回的提示信息
    private String msg ;
    //返回的数据 List Vo类
    private T data ;

    private Result() {}


    private Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    //提供静态的方法，供其他类使用
    public static <T> Result<T> success(T data) {
        return  new Result<>(2000,"success",data) ;
    }
    public static <T> Result<T> success(String msg) {
        return  new Result<>(2000,msg,null) ;
    }
    public static <T> Result<T> success(String msg ,T data) {
        return  new Result<>(2000,msg,data) ;
    }
    public static <T> Result<T> success() {
        return  new Result<>(2000,"操作成功",null) ;
    }

    public static <T> Result<T> fail(String msg) {
        return  new Result<>(4002,msg,null) ;
    }
    public static <T> Result<T> fail() {
        return  new Result<>(4001,"操作失败",null) ;
    }
    public static <T> Result<T> fail(Integer code ,String msg) {
        return  new Result<>(code,msg,null) ;
    }
}
